program q127;
var
    i, j, n, len, a, b, t, ans: longint;
    s: string;
function pow(a, b:longint):longint;
var
    re, i: longint;
begin
    re := 1;
    for i:=1 to b do
    begin
        re := re * a;
    end;

    pow := re;
end;
begin
    assign(input, '');
    assign(output, '');
    reset(input);
    rewrite(output);

    while (not seekeof) do
    begin
        readln(n);
        ans := 0;
        for i:=1 to n do
        begin
            readln(s);

            j := 1; a := 0;
            while (s[j] <> '(') do
            begin
                a := a * 10 + ord(s[j]) - ord('0');
                j := j + 1;
            end;
            len := j-1;
            j := j + 1;
            b := 0;
            while (s[j] <> ')') do
            begin
                b := b * 10 + ord(s[j]) - ord('0');
                j := j + 1;
            end;

            t := 0;
            for j:=1 to len do
            begin
                t := t + ((a mod 10) * pow(b, (j - 1)));
                a := a div 10;
            end;
            ans := ans + t;
        end;

        writeln(ans);
    end;

    close(input);
    close(output);
end.
